package com.example.administrator.myapplication.net;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.example.administrator.myapplication.R;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitActivity extends AppCompatActivity {
    private static final String TAG = "Retrofit";
    private static final String BASE_URL = "http://www.izaodao.com/Api/";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit2);
        retrofitTest();
    }

    private void retrofitTest() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        final ServiceInterface service = retrofit.create(ServiceInterface.class);
        final Call<RetrofitEntity> call = service.getAllVideo(true);
        call.enqueue(new Callback<RetrofitEntity>() {
            @Override
            public void onResponse(Call<RetrofitEntity> call, Response<RetrofitEntity> response) {
                final RetrofitEntity entity = response.body();
                Log.d(TAG, entity.getMsg());
            }

            @Override
            public void onFailure(Call<RetrofitEntity> call, Throwable t) {

            }
        });
    }

}
